package top.wineye.spring.bean.definition;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import top.wineye.model.User;

/**
 * {@link org.springframework.beans.factory.config.BeanDefinition} bean definition creation demo
 */
public class BeanDefinitionCreation {

    public static void main(String[] args) {

        // 1. 通过 BeanDefinitionBuilder 方式
        BeanDefinitionBuilder beanDefinitionBuilder =
                BeanDefinitionBuilder.genericBeanDefinition(User.class);

        beanDefinitionBuilder
                .addPropertyValue("id", 1)
                .addPropertyValue("name", "wineye");

        // 2. 通过 AbstractBeanDefinition 派生类

        GenericBeanDefinition genericBeanDefinition =
                new GenericBeanDefinition();
        genericBeanDefinition.setBeanClass(User.class);
        MutablePropertyValues propertyValues = new MutablePropertyValues();
        propertyValues
                .add("id", 1)
                .add("name", "wineye");
        genericBeanDefinition.setPropertyValues(propertyValues);

    }
}
